<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>注册</title>
		<link rel="stylesheet" type="text/css" href="css/public.css"/>
		<link rel="stylesheet" type="text/css" href="css/login.css"/>
		<script src="js/jquery-3.4.1.js"></script>
		<style type="text/css">
			.check-a{
				color: #0BB20C;
			}
			.check-b{
				color: #F23030;
			}
		</style>
	</head>
	<body>
		<!-------------------reg-------------------------->
		<div class="reg">
			<form action="${pageContext.request.contextPath}/register" method="post">
				<h1><a href="allType?action=all&tid=0&keyWord="><img src="img/logo.png" style="width:100px;height:50px"></a></h1>
				<p>用户注册</p>
				<p><input  id="unikename" type="text" name="unikename" value="" placeholder="请输入用户名" required="required"></p><span id="check"></span>
				<p><input  id="password1" type="password" name="upassword" value="" placeholder="请输入密码" required="required"></p>
				<p><input  id="password2" type="password" name="tPassword" value="" placeholder="请确认密码" required="required"></p><span id="psd"></span>
				<p class="txtL txt"><input id="code" class="code" type="text" name="check" value="" placeholder="验证码" required="required"><img id="checkImg" src="${pageContext.request.contextPath}/checkImg?date=new Date()"></p><span id="Img"></span>
				<p><input id="submit" type="submit" name="" value="注册" onsubmit="return onsubmit()"></p>
				<p class="txtL txt">完成此注册，即表明您同意了我们的<a href="#">《使用条款和隐私策略》</a></p>
				<p class="txt"><a href="login.jsp"><span></span>已有账号登录</a></p>
				<!--<a href="#" class="off"><img src="img/temp/off.png"></a>-->
			</form>
		</div>
		<script src="js/jquery-3.4.1.js"></script>
		<script>
			//点击更新验证码
			$("#checkImg").click(function(){
				$(this).attr("src","${pageContext.request.contextPath}/checkImg?date="+new Date());
			});

			function checkuNikeName(){
				var unikename = $("#unikename").val();
				if (unikename == ""){
					$("#check").text("用户名不能为空！");
					$("#check").addClass("check-b");
				}
				$.ajax({
					url : "${pageContext.request.contextPath}/checkuNikeName/"+unikename,
					type : "GET",
					// dataType : "json",
					success : function(data){
						if (data == "true"){
							$("#check").text("");
						}else{
							$("#check").text("重复！");
							$("#check").addClass("check-b");
							$("#check").removeClass("check-a");
						}
					}
				});
			}

			$("#unikename").blur(function(){
				checkuNikeName();
			});

			$("#password2").blur(function(){
				var psd1 = $("#password1").val();
				var psd2 = $("#password2").val();
				if (psd1 != psd2){
					$("#psd").text("密码不一致！");
					$("#psd").addClass("check-b");
				} else{
					$("#psd").text("");
				}
			});

			<%--$("#code").blur(function(){--%>
				<%--var code = $("#code").val();--%>
				<%--$.ajax({--%>
					<%--url : "${pageContext.request.contextPath}/getCode",--%>
					<%--type : "Get",--%>
					<%--success : function(data){--%>
						<%--if (code == data){--%>
							<%--$("#Img").text("");--%>
						<%--}else {--%>
							<%--$("#Img").text("验证码错误");--%>
							<%--$("#Img").addClass("check-b");--%>
						<%--}--%>
					<%--}--%>
				<%--})--%>
			<%--});--%>

			function onsubmit(){
				if($("#check").val() == "" && $("#psd").val() == "" && $("#Img").val() == "" && $("#unikename").val() != "" && $("#unikename").val() != null){
					return true;
				}else{
					return false;
				}
			}


		</script>
	</body>
</html>
